package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.GeussWelViewPagerAdapter;
import liumengbaio.lolzhangyoubao.Activity.Fragment.GeussWelLastListFragment;
import liumengbaio.lolzhangyoubao.Activity.Fragment.GeussWelNowListFragment;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/12.
 */
public class GeussWelActivity extends AppCompatActivity implements View.OnClickListener {
    private Button now_list, last_list, edit_head_left_title;
    private GeussWelNowListFragment nowListFragment;
    private GeussWelLastListFragment lastListFragment;
    private GeussWelViewPagerAdapter adapter;
    private ViewPager vp;
    private List<Fragment> lists;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gess_wel_activity);
        initView();
        initData();
    }

    private void initData() {
        last_list.setOnClickListener(this);
        now_list.setOnClickListener(this);
        edit_head_left_title.setOnClickListener(this);
        adapter = new GeussWelViewPagerAdapter(getSupportFragmentManager(), lists);
        vp.setAdapter(adapter);
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if(position==0){
                    last_list.setBackgroundColor(Color.TRANSPARENT);
                    now_list.setBackgroundColor(Color.parseColor("#318aff"));
                }else{
                    last_list.setBackgroundColor(Color.parseColor("#318aff"));
                    now_list.setBackgroundColor(Color.TRANSPARENT);
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initView() {
        edit_head_left_title = (Button) findViewById(R.id.edit_head_left_title);
        last_list = (Button) findViewById(R.id.last_list);
        now_list = (Button) findViewById(R.id.now_list);
        nowListFragment = new GeussWelNowListFragment();
        lastListFragment = new GeussWelLastListFragment();
        vp = (ViewPager) findViewById(R.id.geuss_viewpager);
        lists = new ArrayList<>();
        lists.add(nowListFragment);
        lists.add(lastListFragment);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.edit_head_left_title:
                finish();
                break;
            case R.id.last_list:
                last_list.setBackgroundColor(Color.parseColor("#318aff"));
                now_list.setBackgroundColor(Color.TRANSPARENT);
                vp.setCurrentItem(1);
                break;
            case R.id.now_list:
                last_list.setBackgroundColor(Color.TRANSPARENT);
                now_list.setBackgroundColor(Color.parseColor("#318aff"));
                vp.setCurrentItem(0);
                break;
            case R.id.geuss_viewpager:
                break;
        }
    }
}
